window.onload = function(){
    var url = '/withdraw/index';
    var config = {
        elem: '#test'
        ,url:url
        ,cols: [[
            {field:'id', width:80, title: 'id', sort: true}
            ,{field:'withdraw_no', width:150, title: '订单号'}
            ,{field:'shop_id', width:80, title: '店铺id',sort:true}
            ,{field:'shop_name', width:150, title: '店铺名称'}
            ,{field:'shop_phone', width:150, title: '联系电话'}
            ,{field:'withdraw_money', width:100, title: '提现金额'}
            ,{field:'create_time', title: '完成时间',width: 150,templet:function (item) {
                    return timestampToTime(parseInt(item.create_time));
                }}
            ,{field:'withdraw_status', title: '状态', width: 80,templet:function(item){
                    switch (parseInt(item.withdraw_status)){
                        case 0: return '待审核';break;
                        case 1: return '未通过';break;
                        case 2: return '提现中';break;
                        case 3: return '已完成';break;
                        case 4: return '提现失败';break;
                    }
                }}
            ,{fixed: 'right', minWidth:80, title:'操作',align:'center', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器

        ]]
        ,page: true
    };
    layui.use(['form','layer','jquery','table','laydate'], function(){
        var table = layui.table,
            form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            operation = {
                "payMoney":function (data) {
                    Utils.layer.closeAll();
                    Utils.layer.load(1,{'shade':0.5});
                    $.ajax({
                        url: '/withdraw/pay-money',
                        data:data,
                        method:'post',
                        dataType:'json',
                        success:function (data) {
                            Utils.layer.closeAll();
                            Utils.layer.msg(data.msg);
                            table.render(config);
                        }
                    });
                    return true;
                },
            };

        table.render(config);
        //监听工具条
        table.on('tool(barDemo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (layEvent){
                case 'detail':
                    location.href = '/withdraw/info?id='+data.id;break;
                case 'pay-money':
                    Utils.layer.confirm('您确认要执行该操作?',function () {
                        Utils.layer.closeAll()
                        operation.payMoney({
                            id: data.id
                        })
                    });
                    return false;
            }
        });

        //搜索
        form.on("submit(serch-form)",function(data){
            var query = $("#form1").serialize();
            var url = '/withdraw/index?' + query;
            config.url = url;
            table.render(config);
            return false;
        });
        //选择时间
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start_time'
        });
        laydate.render({
            elem: '#end_time'
        });



    });


};

